package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/business/inStock")
public class InStockController {

    @Autowired
    private InStockService inStockService;

    //查询入库纪录
    @GetMapping("/findInStockList")
    public ResponseBean<PageVO<InStockVO>> findInStockList(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                           @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                                                           InStockVO inStockVO) {
        PageVO<InStockVO> inStockVOList = inStockService.findInStockList(pageNum, pageSize, inStockVO);
        return ResponseBean.success(inStockVOList);
    }

    //查看入库单明细
    @GetMapping("/detail/{id}")
    public ResponseBean<InStockDetailVO> detail(@PathVariable Long id, @RequestParam(value = "pageNum") Long pageNum) {
        InStockDetailVO inStockDetailVO = inStockService.detail(id, pageNum);
        return ResponseBean.success(inStockDetailVO);
    }

    //添加(入库)
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody Map addRuleForm) {
        inStockService.addIntoStock(addRuleForm);
        return ResponseBean.success();
    }

    //移除到回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id) {
        inStockService.remove(id);
        return ResponseBean.success();
    }

    //从回收站还原物资信息
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id) {
        inStockService.back(id);
        return ResponseBean.success();
    }

    //审核入库纪录通过
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id) {
        inStockService.publish(id);
        return ResponseBean.success();
    }

    //删除入库纪录
    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        inStockService.delete(id);
        return ResponseBean.success();
    }
}
